package com.lzq.streamdemo.stream;

import com.lzq.streamdemo.entity.Man;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

public class StreamMiddleMethod {
    public static void main(String[] args) {
        //filter 过滤
/*        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,5,6,7,8,9,10);
        list.stream().filter(num->num>5).forEach(System.out::println);*/

        //limit 获取前几个元素
/*        List<Integer> list2 = new ArrayList<>();
        Collections.addAll(list2,1,2,3,4,5,6,7,8,9,10);
        list2.stream().limit(3).forEach(System.out::println);*/

        //skip 跳过前几个元素
/*        List<Integer> list3 = new ArrayList<>();
        Collections.addAll(list3,1,2,3,4,5,6,7,8,9,10);
        list3.stream().skip(3).forEach(System.out::println);*/

        //distinct 去重
/*        List<Integer> list4 = new ArrayList<>();
        Collections.addAll(list4,1,1,1,1,2,3,4,5,6,7,8,9,10);
        list4.stream().distinct().forEach(System.out::println);*/

        //concat 合并两个流
/*        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        Collections.addAll(list1,"111","abc");
        Collections.addAll(list2,"333","def");
        Stream.concat(list1.stream(), list2.stream()).forEach(System.out::println);*/

/*        List<String> list1 = new ArrayList<>();
        Integer[] arr1 = {1,2,3,4,5};
        Collections.addAll(list1,"111","abc");
        Stream.concat(list1.stream(), Arrays.stream(arr1)).forEach(System.out::println);*/

        //map 对象转化
        List<String> list = new ArrayList<>();
        Collections.addAll(list,"180","170","165");
        list.stream().map(new Function<String, Object>() {
            @Override
            public Object apply(String s) {
                Man man = new Man(20,Integer.parseInt(s));
                return man;
            }
        }).forEach(System.out::println);

        list.stream().map(s->{
            Man man = new Man(20,Integer.parseInt(s));
            return man;
        }).forEach(System.out::println);
    }
}
